/**
 * 产品修改js
 */
var comValidform = null;
var returnStatus = false;
var statistics = {
    curPage : 1,
    pageSize : 25,
    dataCache : null,
    totalInfo : null,
    startEvent : function() {
        var url = 'mgr/ProductInfoCtrl/getParProdInfoList';
        var params = {
            'prodTopType':2
        };
        var cb = function(data) {
            if (data.resultCode == 200) {
                var option = '<option value="">请选择产品父标</option>';
                for (var i = 0; i < data.result.length; i++) {
                    var singleObj = data.result[i];
                    option = option + '<option value="' + singleObj.id + '">'
                        + singleObj.name + '</option>';
                }
                $('select[name="parId"]').append(option);
            }
        };
        sendApiNoLoadSync(url, params, cb, 'POST');
    },
    // 查询
    search : function(pageIdx) {
        var url = 'mgr/StatisticsCtrl/getAllInfoNum';
        if (typeof (pageIdx) != "undefined") {
            statistics.curPage = pageIdx;
        }

        var orgName = $.trim($('#searchModForm input[name="orgName"]').val());
        var parId = $.trim($('#searchModForm select[name="parId"]').val());
        var startTime = $.trim($('#searchModForm input[name="startTime"]')
                .val());
        var endTime = $.trim($('#searchModForm input[name="endTime"]').val());

        var params = {
            'curPage' : statistics.curPage,
            'pageSize' : statistics.pageSize,
            'orgName' : orgName,
            'parId' : parId,
            'startTime' : startTime,
            'endTime' : endTime
        };

        var cb = function(data) {
            $('#tableList tbody').empty();
            var tr = '';
            if (data.resultCode == 200) {
                if (data.result != null && data.result.length > 0) {

                    // 输出全部内容
                    for (var i = 0; i < data.result.length; i++) {
                        var singleObj = data.result[i];
                        tr += '<tr   id=' + singleObj.topName + '><td>'
                                + singleObj.topName + '</td><td>'
                                + singleObj.showName + '</td><td>'
                                + singleObj.financialPlannerNum + '</td><td>'
                                + singleObj.financialAppNum + '</td><td>'
                                + singleObj.relationUserAccount + '</td><td>'
                                + singleObj.tiedCardUserAccount + '</td><td>'
                                + singleObj.bespeakOrderNum + '</td><td>'
                                + singleObj.bespeakOrderAmount + '</td><td>'
                                + singleObj.payOrderNum + '</td><td>'
                                + singleObj.payOrderAmount + '</td><td>'
                                + singleObj.niggerAmmount + '</td>'
                                + '</tr>';
                    }
                }

                $('#tableList tbody').html(tr);


                // 合并单元格
                var arr = $("#tableList  tr td:first-child");
                for (var i = 0; i < arr.length - 1;) {
                    var rowSpanNum = 1;
                    var checkSame = true;
                    for(var j= i + 1; j< arr.length && checkSame; j++){
                        if($(arr[j]).text() == $(arr[i]).text()){
                            rowSpanNum ++;
                            $(arr[j]).remove();
                        }else{
                            if(rowSpanNum > 1){
                                //alert("合并前 i == " + i + " rowSpanNum = " + rowSpanNum);
                                $(arr[i]).attr("rowSpan", rowSpanNum );

                            }

                            i = j;
                            checkSame = false;
                            //alert("合并后 i == " + i + " rowSpanNum = " + rowSpanNum);
                        }

                    }
                }
            } else {
                tr = '<tr><td colspan="7" style="text-align: center;color: red;">暂无数据</td></tr>';
            }


        };
        sendApiNoLoad(url, params, cb, 'POST');
    },

    bindEvent : function() {
        // 查询
        $('#searchData').click(function() {
            statistics.search();
        });
    },

    init : function() {
        // set default search date as today
        var today = $.datepicker.formatDate('yy-mm-dd', new Date());

        $('#startTime').val(today);
        $('#endTime').val(today);
        //console.log($('#beginDate').val()+' '+$('#endDate').val()) ;

        statistics.search();
        statistics.startEvent();
        statistics.bindEvent();
        jsUtils.controlFunctionBtn();
    }
}
$(document).ready(function() {
    statistics.init();
});
function submitForm() {
    comValidform.submitForm();
    return returnStatus;
}